<html>
<head><meta charset="utf-8"><title>Spitballing: a `move(x)` expression? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html">Spitballing: a `move(x)` expression?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212331245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212331245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212331245">(Oct 05 2020 at 17:30)</a>:</h4>
<p>I was just writing <code>{v}.pop()</code>, in venerable <a href="https://bluss.github.io/rust/fun/2015/10/11/stuff-the-identity-function-does/#rust-has-dedicated-syntax-for-this">https://bluss.github.io/rust/fun/2015/10/11/stuff-the-identity-function-does/#rust-has-dedicated-syntax-for-this</a> style, and agreeing with the blog post that it might be nice to have a less-abstruse way to write that.</p>
<p>Since we have <code>drop(x)</code>, maybe we could have <code>move(x)</code> too?  It'd need to be in the grammar, because keyword, but maybe that's ok?  It seems like it's probably unambiguous in the grammar, the only confusion that pops to mind is that <code>move(|| x)</code> and <code>(move || x)</code> would be different.</p>
<p>(I picked parens instead of braces because it applies to the result of the expression, not to the expression as a whole.)</p>



<a name="212332023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212332023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212332023">(Oct 05 2020 at 17:37)</a>:</h4>
<p>If <code>::core::convert::identity</code> was in the prelude we'd already have some basic alternative, but I do agree that the word <em>move</em> is the one best conveying the desired semantics. Other option being <code>moved</code> and <code>by_move</code>, which have the advantage of not requiring a keyword, just an added function to prelude (which is also something desirable; one thing I love about <code>drop</code> in Rust is how it is simultaneously the simplest function you can write, and yet one with important semantics <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span>)</p>



<a name="212333763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212333763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212333763">(Oct 05 2020 at 17:52)</a>:</h4>
<p>I'm not a fan of <code>identity(v).pop()</code> because my first reaction to that is "why did you use identity there?" -- like it would be possible to <code>{v};</code> or <code>identity(v);</code> instead of <code>drop(v);</code>, but I wouldn't want to.</p>



<a name="212348427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212348427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212348427">(Oct 05 2020 at 19:55)</a>:</h4>
<p>I'd hate to have that function invite comparisons to C++ <code>std::move</code></p>



<a name="212348544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212348544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212348544">(Oct 05 2020 at 19:56)</a>:</h4>
<p>Rust's move semantics are so much simpler</p>



<a name="212351488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212351488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212351488">(Oct 05 2020 at 20:21)</a>:</h4>
<p>That's true; would definitely want it to come along with warnings for <code>foo(move(v))</code> or <code>x = move(y);</code> to tell people they didn't need it there.</p>



<a name="212351842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212351842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212351842">(Oct 05 2020 at 20:24)</a>:</h4>
<p>I suppose I could just write <code>{v}.pop()</code> as <code>{ let v = v; v.pop() }</code> instead, though that's not all that intuitive either, just longer...</p>



<a name="212362699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212362699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212362699">(Oct 05 2020 at 22:09)</a>:</h4>
<p>Honestly, the times I've wanted something like <code>move</code> on one expression, it's been in the middle of a lambda, where I want to move some but not all of the captures of that lambda.</p>



<a name="212362722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212362722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212362722">(Oct 05 2020 at 22:09)</a>:</h4>
<p>So it still couldn't have just been added to an individual expression in those cases.</p>



<a name="212400296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212400296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212400296">(Oct 06 2020 at 08:53)</a>:</h4>
<blockquote>
<p>I suppose I could just write <code>{v}.pop()</code> as <code>{ let v = v; v.pop() }</code> instead, though that's not all that intuitive either, just longer...</p>
</blockquote>
<p>Funnily enough, you got the second one wrong <span aria-label="grinning face with smiling eyes" class="emoji emoji-1f601" role="img" title="grinning face with smiling eyes">:grinning_face_with_smiling_eyes:</span> I mean yes, we can just go and <code>let mut v = v</code> rebind the value.</p>
<p>The purpose of offering a renamed <code>identity</code> (as <code>moved</code> or <code>by_move</code>) would be twofold: on the one hand, as you pointed out, <code>identity(v).pop()</code> doesn't look better than <code>{v}.pop()</code>, and on the other hand, for anybody making a comparison to <code>std::move()</code>, we'd have at least the fact that "our" implementation of <code>move</code> is just the identity function (granted, <code>std::move()</code> is just a cast), so that we know there is no magic going on there. I'd say that the fact that a binding can be "reluctant to being accessed exclusively"  (I don't like to say immutable, since <code>let x = Cell::new(42);</code> isn't immutable) _vs._ a temporary / rvalue not being so, has kind of already sailed the ship in that regard.</p>



<a name="212403377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212403377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212403377">(Oct 06 2020 at 09:27)</a>:</h4>
<p>we can make <code>move(x)</code> syntax sugar (lol?) for <code>{x}</code>, so it's not even a function that you can import</p>



<a name="212427171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212427171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212427171">(Oct 06 2020 at 13:29)</a>:</h4>
<p>that seems like too much magic IMO</p>



<a name="212427248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212427248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212427248">(Oct 06 2020 at 13:30)</a>:</h4>
<p>it would be easy to get confused and think you <em>needed</em> move to move things</p>



<a name="212432630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212432630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212432630">(Oct 06 2020 at 14:09)</a>:</h4>
<p>If we don't want it to be a function, I'd keep using it like a keyword operator, <code>move expr</code>. But that means <code>(move v).pop()</code>.</p>



<a name="212432815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212432815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212432815">(Oct 06 2020 at 14:10)</a>:</h4>
<p>Closures could be wrapped to disambiguate it, <code>move (|| ...)</code>, but there's also no reason to use it that way</p>



<a name="212434820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212434820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212434820">(Oct 06 2020 at 14:23)</a>:</h4>
<p>I like that a lot!</p>



<a name="212463117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463117">(Oct 06 2020 at 18:00)</a>:</h4>
<p>Clearly then it just needs to be <code>v.move.pop()</code>, <span class="user-mention" data-user-id="138448">@cuviper</span> <span aria-label="smirk" class="emoji emoji-1f60f" role="img" title="smirk">:smirk:</span></p>
<p>Which does actually remove the closure ambiguity <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="212463218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463218">(Oct 06 2020 at 18:01)</a>:</h4>
<p>oh man, whatever happened to making more postfix keywords?</p>



<a name="212463253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463253">(Oct 06 2020 at 18:01)</a>:</h4>
<p><code>.match</code> came up a lot when justifying <code>.await</code>.</p>



<a name="212463534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463534">(Oct 06 2020 at 18:03)</a>:</h4>
<p>Actually, I like this more than my original proposal.  It meets my "this takes the result of the expression rather than impacting all the code in the region" criteria for fitting well as postfix.</p>



<a name="212463912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463912">(Oct 06 2020 at 18:06)</a>:</h4>
<p>IIRC we explicitly said that <code>.match</code> was a reasonableness argument, not an actual plan to do something there.</p>



<a name="212463956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212463956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212463956">(Oct 06 2020 at 18:07)</a>:</h4>
<p>Not that I'd be opposed to exploring it more seriously</p>



<a name="212471368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212471368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212471368">(Oct 06 2020 at 19:08)</a>:</h4>
<p>Isn't <code>move x</code> actual syntax in MIR?</p>



<a name="212495783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212495783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212495783">(Oct 06 2020 at 22:51)</a>:</h4>
<p>Well, there's <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.Operand.html"><code>Operand::Move</code></a> certainly.  The MIR syntax doesn't really matter, since it's unstable, doesn't have a parser, and doesn't nest or chain so the constraints on it are completely different.</p>



<a name="212495867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212495867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212495867">(Oct 06 2020 at 22:52)</a>:</h4>
<p>Actually, an interesting possibility: <code>.move</code> could <em>always</em> be a move, rather than being a copy for <code>Copy</code> types.</p>



<a name="212496212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212496212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212496212">(Oct 06 2020 at 22:58)</a>:</h4>
<p>Would make <code>let _ = x.move;</code> a way to keep <code>x</code> from being used again more obviously than the current <code>let x: !;</code> shadowing approach.</p>



<a name="212496248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212496248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212496248">(Oct 06 2020 at 22:58)</a>:</h4>
<p>that's <code>drop(x)</code>, no?</p>



<a name="212496276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212496276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212496276">(Oct 06 2020 at 22:59)</a>:</h4>
<p>also, while I'm grumbling, I think having <code>let _ = f();</code> drop immediately but <code>let _ = x;</code> do nothing is <em>super</em> confusing</p>



<a name="212496388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212496388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212496388">(Oct 06 2020 at 23:00)</a>:</h4>
<p>oh I guess <code>drop</code> wouldn't do anything for <code>Copy</code> types though</p>



<a name="212496395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212496395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212496395">(Oct 06 2020 at 23:00)</a>:</h4>
<p>that seems a little niche</p>



<a name="212497250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212497250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212497250">(Oct 06 2020 at 23:12)</a>:</h4>
<p>I've definitely wanted a way to move a value that is <code>Copy</code> before</p>



<a name="212573828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212573828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212573828">(Oct 07 2020 at 15:16)</a>:</h4>
<p>Also, one way a <code>.move</code> expression could be useful, would be if it could also have the semantics of the <code>drop_guards!</code> macro of the following post: <a href="https://users.rust-lang.org/t/while-let-borrow-lifetime-seems-to-be-too-long/49784/5?u=yandros">https://users.rust-lang.org/t/while-let-borrow-lifetime-seems-to-be-too-long/49784/5?u=yandros</a></p>



<a name="212575518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212575518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212575518">(Oct 07 2020 at 15:26)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> so you want to use <code>v.borrow_mut().move.pop()</code> in that example?</p>



<a name="212575603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212575603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212575603">(Oct 07 2020 at 15:27)</a>:</h4>
<p>I don't know, I think it would be even more confusing if this didn't follow normal lifetime rules for temporaries in an expression</p>



<a name="212576475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212576475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212576475">(Oct 07 2020 at 15:33)</a>:</h4>
<p>I was thinking of <code>rc.borrow_mut().pop().move</code>, that is, give <code>&lt;expr&gt;.move</code> the semantics of <code>{ let it = &lt;expr&gt;; it }</code>. This enables a second usage on top of the aforementioned <code>non_mut_var_name.move.pop()</code>, which also justifies having that as a postfix expression (Otherwise there is little reason not to use <code>(move var_name)</code>, since applying it to an <code>rvalue</code> would be a complete no-op).</p>
<p>Basically, the current situation with <code>while let Some(x) = rc.borrow_mut().pop()</code> is quite unfortunate, and I can't come up with a better way to solve that one than a special tool to express dropping temporaries. So, if we were to commit a full-fledged postfix keyword for the <code>{v}.pop()</code>, I think that also covering <code>{ let it = rc.borrow_mut().pop(); it }</code> would be a nice added benefit <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="212576849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212576849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212576849">(Oct 07 2020 at 15:35)</a>:</h4>
<p>that's interesting</p>



<a name="212577126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212577126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212577126">(Oct 07 2020 at 15:37)</a>:</h4>
<p><code>.move</code> so far would apply to the same things that the borrow checker tracks, i.e. <a href="https://rustc-dev-guide.rust-lang.org/borrow_check/moves_and_initialization.html">https://rustc-dev-guide.rust-lang.org/borrow_check/moves_and_initialization.html</a></p>



<a name="212577227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212577227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212577227">(Oct 07 2020 at 15:38)</a>:</h4>
<p>your suggestion is a different scope, I think, but I can see the need</p>



<a name="212578155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212578155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212578155">(Oct 07 2020 at 15:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F/near/212577227">said</a>:</p>
<blockquote>
<p>your suggestion is a different scope, I think, but I can see the need</p>
</blockquote>
<p>I do agree that the semantics may not be that obvious for this second use case though <span aria-label="slight frown" class="emoji emoji-1f641" role="img" title="slight frown">:slight_frown:</span>. But it's hard to come with any other kind of workaround whatsoever <span aria-label="weary" class="emoji emoji-1f629" role="img" title="weary">:weary:</span></p>



<a name="212584326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212584326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212584326">(Oct 07 2020 at 16:28)</a>:</h4>
<p>Bleh, temporaries.</p>
<p>Yeah, I'd been thinking of this as just introducing a MIR <code>Operand::Move</code>, and linting for uselessly applying it to an <del>rvalue</del>operand instead of an <del>lvalue</del>place.</p>



<a name="212584887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212584887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212584887">(Oct 07 2020 at 16:32)</a>:</h4>
<p>I think I see the postfix-ness of it opposite to how you do, though, <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span>.</p>
<p>To me it makes sense because it doesn't affect the whole expression, just the result.  For something that affects temporaries I'd expect to be able to express <code>drop_guards! { v.borrow_mut().pop() }</code> vs <code>drop_guards! { v.borrow_mut() }.pop()</code>, and I don't think that's reasonable with <code>.move</code>.</p>



<a name="212588024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212588024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212588024">(Oct 07 2020 at 16:58)</a>:</h4>
<p>(AKA exactly the same issue that was the stumbling block for postfix macros in general.)</p>
<p>So I think if we went that way it would be a "move block".  Which could totally work, <code>move{v}.pop()</code> it's terrible.</p>
<p>But I don't know that I'd pick <code>move</code> as the token for that feature.  It doesn't obviously say "changes the lifetime rules" to me.  I was thinking more in the <code>v.move</code> vs <code>v.clone()</code> vs <code>v.as_ref()</code> way.</p>



<a name="212589050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212589050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212589050">(Oct 07 2020 at 17:05)</a>:</h4>
<p>I think other keywords could be explored for the "de-temp" case, like maybe <code>do { v.borrow_mut().pop() }</code></p>



<a name="212601447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212601447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212601447">(Oct 07 2020 at 18:42)</a>:</h4>
<p>True, though I feel like <code>library_bikeshed_here! { v.borrow_mut().pop() }</code> might be ok for that, since "add a <code>let</code>" apparently has the desired semantics.  And it's a rather nuanced operation, so a long name seems fine.  (Whereas there's no way to move-not-copy a <code>Copy</code> place right now.)</p>



<a name="212603381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212603381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212603381">(Oct 07 2020 at 18:57)</a>:</h4>
<p>is the intent that "move" also moves <code>copy</code> things?</p>



<a name="212603412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212603412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212603412">(Oct 07 2020 at 18:57)</a>:</h4>
<p>i.e., <code>let x = 22; move(x); move(x)</code> is an error?</p>



<a name="212604164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604164">(Oct 07 2020 at 19:02)</a>:</h4>
<p>that's the current thought, yes</p>



<a name="212604244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604244">(Oct 07 2020 at 19:02)</a>:</h4>
<p>it would move/invalidate any place, regardless of <code>Copy</code></p>



<a name="212604374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604374">(Oct 07 2020 at 19:03)</a>:</h4>
<p>the initial motivation didn't require that though, formalizing the "move" effect of <code>{v}.pop()</code></p>



<a name="212604661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604661">(Oct 07 2020 at 19:05)</a>:</h4>
<p>yeah.</p>



<a name="212604735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604735">(Oct 07 2020 at 19:06)</a>:</h4>
<p>we used to have this and removed it :)</p>



<a name="212604748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604748">(Oct 07 2020 at 19:06)</a>:</h4>
<p>(not to say we can't add it back)</p>



<a name="212604834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212604834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212604834">(Oct 07 2020 at 19:06)</a>:</h4>
<p>I know <span class="user-mention" data-user-id="116083">@pnkfelix</span> is always a fan of being able to be explicit when you need it ...</p>



<a name="212605283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605283">(Oct 07 2020 at 19:10)</a>:</h4>
<p>what did it look like before?</p>



<a name="212605302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605302">(Oct 07 2020 at 19:10)</a>:</h4>
<p>/me tries to remember</p>



<a name="212605334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605334">(Oct 07 2020 at 19:10)</a>:</h4>
<p>I think it was just <code>move x</code>, but we also had "move mode" for arguments... maybe I'm remembering wrong</p>



<a name="212605493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605493">(Oct 07 2020 at 19:12)</a>:</h4>
<p>in case you missed the pivot, <span class="user-mention" data-user-id="125270">@scottmcm</span> is suggesting this as a postfix keyword now, <code>x.move</code></p>



<a name="212605560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605560">(Oct 07 2020 at 19:12)</a>:</h4>
<p>I did see that</p>



<a name="212605568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212605568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212605568">(Oct 07 2020 at 19:12)</a>:</h4>
<p>interesting :)</p>



<a name="212606577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212606577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212606577">(Oct 07 2020 at 19:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F/near/212604244">said</a>:</p>
<blockquote>
<p>it would move/invalidate any place, regardless of <code>Copy</code></p>
</blockquote>
<p>Is there any use case for this, btw? I was just thinking that the initial motivation was <code>{v}.pop()</code> being ugly, but what happens if somebody had a <code>.pop()</code> method for <a href="https://docs.rs/tinyvec/1.0.1/tinyvec/struct.ArrayVec.html#impl-Copy">a <code>Copy</code> receiver</a>? They wouldn't be able to use this neat <code>(move v).pop()</code> / <code>v.move.pop()</code> since it would happen to also invalidate their initial copy. And if they were doing <code>{copy_thingy}.pop()</code> to begin with it was precisely because they did not want to alter their initial <code>Copy</code> value, right?</p>
<ul>
<li>In other words, there is something that fundamentally does not feel right about being able to invalidate a thing that has the trait <code>CannotBeInvalidated / Pod / Copy</code>. An actual use case would thus greatly help soothe this feeling <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></li>
</ul>



<a name="212607991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212607991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212607991">(Oct 07 2020 at 19:30)</a>:</h4>
<p>Note that the reason for <code>{v}.pop()</code> originally was to invalidate <code>v</code> -- if I didn't want to invalidate it there's no need for the <code>{}</code>s.  (Basically to act like a <code>self</code>-taking <code>pop</code>, instead of a <code>&amp;mut</code>-taking <code>pop</code>.)</p>
<p>To me, the readable way to call a <code>&amp;mut</code> on something <code>Copy</code> without affecting the original place is <code>v.clone().pop()</code> <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="212608605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212608605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212608605">(Oct 07 2020 at 19:35)</a>:</h4>
<p>I guess one problem with the postfix form is that <code>*</code> should have been postfix -- <code>*x.move</code> is probably not what one wanted.  I wonder how scary it would be as an auto-deref point...</p>



<a name="212608995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212608995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212608995">(Oct 07 2020 at 19:38)</a>:</h4>
<p>I thought it was also for when <code>v</code> isn't already mutable -- then <code>{v}</code> gives you a mutable temporary</p>



<a name="212609559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212609559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212609559">(Oct 07 2020 at 19:43)</a>:</h4>
<p>Hmm, those are definitely two sides of the same coin, but also give a different implication for <code>Copy</code> things.</p>



<a name="212616407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212616407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212616407">(Oct 07 2020 at 20:41)</a>:</h4>
<p>sorry, ICR my original motivation for a move expression since I had wanted it like a year ago since I haven't had as much time to actually write rust recently :(</p>



<a name="212641938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212641938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212641938">(Oct 08 2020 at 02:31)</a>:</h4>
<p>I wonder whether this interacts with the thread about Range being non-Copy, and generally iterators being non-Copy to prevent footguns. It seems the <code>move</code> keyword can address some of the same pain points</p>



<a name="212652734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212652734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212652734">(Oct 08 2020 at 06:55)</a>:</h4>
<p>Oh, interesting.  An edition could change the <code>IntoIterator::into_iter(foo)</code> to <code>IntoIterator::into_iter(foo.move)</code></p>



<a name="212662404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212662404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212662404">(Oct 08 2020 at 08:54)</a>:</h4>
<p>wrong topic <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="212706909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212706909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212706909">(Oct 08 2020 at 15:26)</a>:</h4>
<p>but <code>Copy for Range</code> would still be a footgun in prior editions</p>



<a name="212710133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212710133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212710133">(Oct 08 2020 at 15:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F/near/212652734">said</a>:</p>
<blockquote>
<p>Oh, interesting.  An edition could change the <code>IntoIterator::into_iter(foo)</code> to <code>IntoIterator::into_iter(foo.move)</code></p>
</blockquote>
<p>ooh I really like that</p>



<a name="212710229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212710229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212710229">(Oct 08 2020 at 15:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F/near/212706909">said</a>:</p>
<blockquote>
<p>but <code>Copy for Range</code> would still be a footgun in prior editions</p>
</blockquote>
<p>I think we could address that with a lint that only runs in previous editions</p>



<a name="212710257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212710257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212710257">(Oct 08 2020 at 15:50)</a>:</h4>
<p>that runs whenever you copy a range</p>



<a name="212726307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212726307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212726307">(Oct 08 2020 at 17:51)</a>:</h4>
<p>Hmm, could simplify that to just linting on <code>for i in something_copy {</code>, suggesting <code>for i in something_copy.move {</code> -- there's no reason that <code>.move</code> would need a new edition.</p>



<a name="212726799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/212726799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#212726799">(Oct 08 2020 at 17:54)</a>:</h4>
<p>only when copying from a place though -- I don't want to write <code>for i in (0..10).move {</code></p>



<a name="213070210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/213070210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#213070210">(Oct 12 2020 at 18:17)</a>:</h4>
<blockquote>
<p>I just want to point out that <code>.move</code> has gained a lot of meanings in this thread. I would hate to teach this</p>
</blockquote>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> Could you elaborate?  I thought this was actually fairly consistent for a spitballing thread, with things like <a href="#narrow/stream/122651-general/topic/In.20a.20closure.2C.20how.20do.20I.20move.20some.20things.20but.20not.20others.3F">its meaning in a closure</a> being an implication of the "forces a place to move, becoming a temporary" semantics, not another meaning.</p>



<a name="213070339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/213070339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#213070339">(Oct 12 2020 at 18:18)</a>:</h4>
<p>That is to say, I hope that the move keyword does not simultaneously get all meanings that were proposed for it</p>



<a name="213070631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/213070631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#213070631">(Oct 12 2020 at 18:21)</a>:</h4>
<p>Moving in a closure seems pretty different to me, given that it logically associates to the closure, not the moved value. It also doesn't interact well with the suggestion to invalidate copy locations (in the sense that they are orthogonal features, although their uses are somewhat in complementary distribution so it wouldn't be a problem except for macros)</p>



<a name="213070639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Spitballing%3A%20a%20%60move%28x%29%60%20expression%3F/near/213070639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Spitballing.3A.20a.20.60move(x).60.20expression.3F.html#213070639">(Oct 12 2020 at 18:21)</a>:</h4>
<p>Ah, the <code>move</code> keyword as a whole, not specifically <code>.move</code>.  I see.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>